'''
https://leetcode.cn/problems/count-subarrays-with-score-less-than-k
'''

from typing import List


class Solution:
    def countSubarrays(self, nums: List[int], k: int) -> int:
        n = len(nums)
        l, r = 0, 0
        cur_sum = 0
        res = 0
        while r < n:
            cur_sum += nums[r]
            while l <= r and cur_sum * (r - l + 1) >= k:
                cur_sum -= nums[l]
                l += 1
            res += r - l + 1
            r += 1
        return res